package com.huanbao.oil.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.huanbao.oil.app.R;
import com.huanbao.oil.app.model.YunXingCanShuResultModel;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class YXcanshuAdapter extends BaseAdapter {
    private LayoutInflater minflater;
    private Context context;
    private List<YunXingCanShuResultModel> data;

    public YXcanshuAdapter(Context context, List<YunXingCanShuResultModel> data) {
        super();
        this.minflater = LayoutInflater.from(context);
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        int size=0;
        if(data!=null){
            size= data.size();
        }
        return size;
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return data.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
//            holder = new ViewHolder();
            convertView = minflater.inflate(R.layout.item_canshu, null);
            holder = new ViewHolder(convertView);//这句变化
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
//		holder.themeId.setText(data.get(position));
//        {
//            "mcgs_time": "2020-01-02 14:20:30",
//                "cur_pump_volume": 235,
//                "sum_pump_volume": 1235,
//                "exhaust_concentration": 0.2,
//                "gas_tank_pressure": 120.2,
//                "system_temperature": 25.2,
//                "analysis_times": 63,
//                "adsorption_temperature": 589,
//        }
        holder.itemCanshu1.setText(data.get(position).getMcgs_time());
        holder.itemCanshu2.setText(String.valueOf(data.get(position).getCur_pump_volume()));
        holder.itemCanshu3.setText(String.valueOf(data.get(position).getSum_pump_volume()));
        holder.itemCanshu4.setText(String.valueOf(data.get(position).getExhaust_concentration()));
        holder.itemCanshu5.setText(String.valueOf(data.get(position).getGas_tank_pressure()));
        holder.itemCanshu6.setText(String.valueOf(data.get(position).getSystem_temperature()));
        holder.itemCanshu7.setText(String.valueOf(data.get(position).getAnalysis_times()));
        holder.itemCanshu8.setText(String.valueOf(data.get(position).getAdsorption_temperature()));
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.item_canshu_1)
        TextView itemCanshu1;
        @BindView(R.id.item_canshu_2)
        TextView itemCanshu2;
        @BindView(R.id.item_canshu_3)
        TextView itemCanshu3;
        @BindView(R.id.item_canshu_4)
        TextView itemCanshu4;
        @BindView(R.id.item_canshu_5)
        TextView itemCanshu5;
        @BindView(R.id.item_canshu_6)
        TextView itemCanshu6;
        @BindView(R.id.item_canshu_7)
        TextView itemCanshu7;
        @BindView(R.id.item_canshu_8)
        TextView itemCanshu8;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
